package fleditor.core.iso
{
	import flash.geom.Point;

	public class IsoUtils
	{
		public static const Y_CORRECT:Number = Math.cos(-Math.PI / 6) * Math.SQRT2;
		
		public static function spaceToScreen(pos:IsoPoint):Point
		{
			var screenX:Number = pos.x - pos.z;
			var screenY:Number = pos.y * Y_CORRECT + (pos.x + pos.z) * .5;
			return new Point(screenX, screenY);
		}
		
		public static function screenToSpace(point:Point):IsoPoint
		{
			var xpos:Number = point.y + point.x * .5;
			var ypos:Number = 0;
			var zpos:Number = point.y - point.x * .5;
			return new IsoPoint(xpos, ypos, zpos);
		}
		
		public static function getGridPoint(pt:IsoPoint, cellSize:Number):IsoPoint
		{
			return new IsoPoint(Math.floor(pt.x/cellSize), 0, Math.floor(pt.z/cellSize));
		}
	}
}